// renwu/xuanzexiangmu/xuanzexiangmu.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    qitaboor: true,
    xiangmuval: "",
    xiangmu: []
  },
  // 选择项目
  selxaingmu(e) {
    //console.log(e)
    var that = this
    var txt = e.currentTarget.dataset.txt;
    var xm_id = e.currentTarget.dataset.xm_id
    var jc_jgtype = e.currentTarget.dataset.jc_jgtype
    var p_id = e.currentTarget.dataset.p_id
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    console.log(p_id, xm_id)
    //查询一条与当前检查项目关联的jgid
    app.util.request({
      'url': 'entry/wxapp/Gtonly',
      data: {
        erjid: p_id,
        jxopenid: wx.getStorageSync('openid'),
        xm_id: xm_id
      },
      success: function(res) {
        console.log(res)
      }
    })
    prevPage.setData({
      txt: txt,
      xm_id: xm_id,
      jc_jgtype: jc_jgtype
    })
    wx.navigateBack({
      delta: 1
    })
  },
  // 显示模态框
  qitabtns() {
    this.setData({
      qitaboor: false
    })
  },
  // 关闭模态框
  closemodal() {
    this.setData({
      qitaboor: true
    })
  },
  // 表单提交
  submitform(e) {
    var val = e.detail.value.xmname;
    if (val == "") {
      wx.showToast({
        title: '请输入项目名称',
      })
    } else {
      console.log(val);
      wx.navigateBack({

      })
    }
    console.log(val);
  },
  // 取消按钮
  restform() {
    this.setData({
      qitaboor: true,
      xiangmuval: "",
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var p_id = options.p_id

    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      p_id: p_id,
      bgc: bgc
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.getAlljcxm()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  getAlljcxm: function() {
    var that = this
    var p_id = that.data.p_id
    app.util.request({
      'url': 'entry/wxapp/Alljcxm',
      data: {
        p_id: p_id
      },
      success: function(res) {
        var xiangmu = res.data.data;
        console.log(res);
        var len = xiangmu.length;
        for (var i = 0; i < len; i++) {
          for (var j = i + 1; j < len; j++) {
            if (xiangmu[i].jc_type == xiangmu[j].jc_type) {
              xiangmu.splice(i, 1);
              j--;
              len--;
            }
          }
        }
        console.log(xiangmu)
        that.setData({
          xiangmu: xiangmu,
        })
      }
    })
  }
})